package com.bw.controller;

import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
import com.bw.service.FoodService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * @author WBS
 * @date 2025年11月10日 上午 11:01
 */

@RestController
public class FoodController {
    @Autowired
    FoodService foodService;

    @RequestMapping("/findJkl")
    public Object findJkl()
    {
        List<Map> list = foodService.findJkl();
        System.out.println(list);
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("status",0);
        jsonObject.put("msg","");
        JSONObject dataObject = new JSONObject();
        JSONArray xArray = new JSONArray();
        for (Map map : list) {
            xArray.add(map.get("n"));
        }
        dataObject.put("categories",xArray);
        JSONArray yArray = new JSONArray();
        JSONObject yObject = new JSONObject();
        yObject.put("name","菜品名称");
        JSONArray Array = new JSONArray();
        for (Map map : list) {
            Array.add(map.get("total"));
        }
        yObject.put("data",Array);
        yArray.add(yObject);
        dataObject.put("series",yArray);
        jsonObject.put("data",dataObject);
        return jsonObject;
    }

    @RequestMapping("/findPro1")
    public Object findPro1(String time)
    {
        List<Map> list = foodService.findPro1(time);
        System.out.println(list);
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("status",0);
        jsonObject.put("msg","");
        JSONObject dataObject = new JSONObject();
        JSONArray jsonArray = new JSONArray();
        for (Map map : list) {
            JSONObject Object = new JSONObject();
            Object.put("name",map.get("n"));
            Object.put("value",map.get("total1"));
            jsonArray.add(Object);
        }
        dataObject.put("mapData",jsonArray);
        dataObject.put("valueName","下单金额");
        jsonObject.put("data",dataObject);
        return jsonObject;
    }

    @RequestMapping("/findPro2")
    public Object findPro2(String time)
    {
        List<Map> list = foodService.findPro2(time);
        System.out.println(list);
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("status",0);
        jsonObject.put("msg","");
        JSONObject dataObject = new JSONObject();

        jsonObject.put("data",dataObject);
        return jsonObject;
    }

    @RequestMapping("/findPro3")
    public Object findPro3(String time)
    {
        List<Map> list = foodService.findPro3(time);
        System.out.println(list);
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("status",0);
        jsonObject.put("msg","");
        JSONObject dataObject = new JSONObject();

        jsonObject.put("data",dataObject);
        return jsonObject;
    }

    @RequestMapping("/findIop")
    public Object findIop(String time)
    {
        List<Map> list = foodService.findIop(time);
        System.out.println(list);
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("status",0);
        jsonObject.put("msg","");
        JSONObject dataObject = new JSONObject();
        JSONArray xArray = new JSONArray();

        JSONObject jsonObject1 = new JSONObject();
        jsonObject1.put("name","活动参与人数");
        jsonObject1.put("id","total");
        xArray.add(jsonObject1);

        JSONObject jsonObject2 = new JSONObject();
        jsonObject2.put("name","活动参与人数");
        jsonObject2.put("id","c1");
        xArray.add(jsonObject2);

        JSONObject jsonObject3 = new JSONObject();
        jsonObject3.put("name","活动参与人数");
        jsonObject3.put("id","c2");
        xArray.add(jsonObject3);

        dataObject.put("columns",xArray);
        JSONArray yArray = new JSONArray();
        for (Map map : list) {
            JSONObject Object = new JSONObject();
            Object.put("total",map.get("total"));
            Object.put("c1",map.get("c1"));
            Object.put("c2",map.get("c2"));
            yArray.add(Object);
        }
        dataObject.put("rows", yArray);
        jsonObject.put("data",dataObject);
        return jsonObject;
    }

    @RequestMapping("/findJkp")
    public Object findJkp(String time)
    {
        List<Map> list = foodService.findJkp(time);
        System.out.println(list);
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("status",0);
        jsonObject.put("msg","");
        JSONObject dataObject = new JSONObject();
        JSONArray xArray = new JSONArray();

        JSONObject jsonObject1 = new JSONObject();
        jsonObject1.put("name","活动参与人数");
        jsonObject1.put("id","n");
        xArray.add(jsonObject1);

        JSONObject jsonObject2 = new JSONObject();
        jsonObject2.put("name","活动参与人数");
        jsonObject2.put("id","total");
        xArray.add(jsonObject2);

        JSONObject jsonObject3 = new JSONObject();
        jsonObject3.put("name","活动参与人数");
        jsonObject3.put("id","t");
        xArray.add(jsonObject3);

        dataObject.put("columns",xArray);
        JSONArray yArray = new JSONArray();
        for (Map map : list) {
            JSONObject Object = new JSONObject();
            Object.put("n",map.get("n"));
            Object.put("total",map.get("total"));
            Object.put("t",map.get("t"));
            yArray.add(Object);
        }
        dataObject.put("rows", yArray);
        jsonObject.put("data",dataObject);
        return jsonObject;
    }


}
